# include <bits/stdc++.h>

const int N=100010,INF=0x3f3f3f3f;

inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-') f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
int n,p[N];

bool vis[N];
int q[N];

int ans=INF;

void dfs(int x,int diff){
	if(diff>ans) return;
	if(x>n) return ans=std::min(ans,diff),void();
	for(int w=1;w<=n;++w){
		if(vis[w]) continue;
		int minx=INF,maxx=-INF;
		q[x]=w;
		for(int y=x-1;y;--y){
			if(minx<std::min(q[x],q[y])&&maxx>std::max(q[x],q[y])) goto END;
			minx=std::min(minx,q[y]);
			maxx=std::max(maxx,q[y]);
		}
		vis[w]=true,dfs(x+1,(q[x]!=p[x])+diff),vis[w]=false;
		END:;
	}
}

int main(void){
	freopen("build.in","r",stdin);
	freopen("build.out","w",stdout);
	n=read();
	for(int i=1;i<=n;++i) p[i]=read();
	dfs(1,0);
	printf("%d",ans);

	return 0;
}